package HRMPROJECT.CONTROLLERS;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.table.DefaultTableModel;

import HRMPROJECT.BASEUTILS.Commons;
import HRMPROJECT.MODELS.EmployeesEntity;
import HRMPROJECT.MODELS.EmployeesModels;
import HRMPROJECT.MODELS.SecurityContexts;

public class EmployeesController {
    private Connection m_objConnection = null;
    private SecurityContexts m_objSecurity = null;
    private EmployeesModels m_objModels = null;

    public EmployeesController(Connection objConnection, SecurityContexts objSecurity) {
        m_objConnection = objConnection;
        m_objSecurity = objSecurity;

        m_objModels = new EmployeesModels(m_objConnection);
    }

    /***
     * Nghiệp vụ hiển thị danh sách nhân viên
     * @return
     * @throws SQLException 
     */
    public ResultSet getEmployeeAll() throws SQLException {
        return m_objModels.getElementAll();
    }

    public ResultSet getEmployeeByDepartId(int DepartId) throws SQLException {
        return m_objModels.getElementById(DepartId);
    }

    /***
     * Nghiệp vụ thêm thông tin nhân viên
     * @param objEntity
     * @return
     * @throws SQLException
     */
    public boolean InsertEmployee(EmployeesEntity objEntity) throws SQLException {
        return m_objModels.InsertElement(objEntity);
    }

    /***
     *Nghiệp vụ cập nhật thông tin nhân viên
     * @param objEntity
     * @return
     * @throws SQLException
     */
    public boolean UpdateEmpoyee(EmployeesEntity objEntity) throws SQLException {
        return m_objModels.UpdateElement(objEntity);
    }

    /***
     * Nghiệp vụ xóa thông tin nhân viên
     * @param objEntity
     * @return
     * @throws SQLException
     */
    public boolean DeleteEmpoyee(EmployeesEntity objEntity) throws SQLException {
        return m_objModels.DeleteElement(objEntity);
    }

    public DefaultTableModel EmployeeTableModels() throws SQLException {
        DefaultTableModel objDtm = null;
        try {
            ResultSet objRs = getEmployeeAll();
            Commons objComs = new Commons();
            objDtm = new DefaultTableModel();
            objDtm = objComs.getModels(objRs);
        } catch (SQLException e) {
            throw e;
        }
        return objDtm;
    }

    public DefaultTableModel EmployeeByIdTableModels(int DepartId) throws SQLException {
        DefaultTableModel objDtm = null;
        try {
            ResultSet objRs = getEmployeeByDepartId(DepartId);
            Commons objComs = new Commons();
            objDtm = new DefaultTableModel();
            objDtm = objComs.getModels(objRs);
        } catch (SQLException e) {
            throw e;
        }
        return objDtm;
    }

}
